#ifndef PIZZA_HPP
#define PIZZA_HPP

#include <iostream>
#include "PizzaIngredientFactory.hpp"

class Pizza
{
protected:
  IngredientFactory *_factory;

public:
  Pizza(IngredientFactory *factory)
      : _factory(factory)
  {
  }

  virtual void Prepare() = 0;
  virtual void Bake() = 0;
  virtual void Cut() = 0;
  virtual void Box() = 0;
};

class NYStyleCheesePizza : public Pizza
{
private:
  std::string _dough;
  std::string _sauce;
  std::string _cheese;

public:
  NYStyleCheesePizza()
      : Pizza(new NYIngredientFactory())
  {
    _dough = _factory->CreateDough();
    _sauce = _factory->CreateSauce();
    // 注意：这里必须要强转，不然调用的是基类的中的CreateCheese接口
    // _cheese = _factory->CreateCheese();
    _cheese = ((NYIngredientFactory *)_factory)->CreateCheese();
  }

  // 获取原料
  void Prepare()
  {
    std::cout << "Prepare" << std::endl;
    std::cout << "dough: " << _dough << std::endl;
    std::cout << "sauce: " << _sauce << std::endl;
    std::cout << "cheese: " << _cheese << std::endl;
    // _cheese = _factory->CreateCheese();
  }

  void Bake()
  {
    std::cout << "正在进行烘培操作" << std::endl;
  }

  void Cut()
  {
    std::cout << "将披萨提前切好" << std::endl;
  }

  void Box()
  {
    std::cout << "包装披萨" << std::endl;
  }

  ~NYStyleCheesePizza()
  {
    delete _factory;
  }
};

class NYStyleVeggiesPizza : public Pizza
{
private:
  std::string _dough;
  std::string _sauce;
  std::string _veggies;

public:
  NYStyleVeggiesPizza()
      : Pizza(new NYIngredientFactory())
  {
    _dough = _factory->CreateDough();
    _sauce = _factory->CreateSauce();
    // 注意：这里必须要强转
    _veggies = ((NYIngredientFactory *)_factory)->CreateVeggies();
  }

  // 获取原料
  void Prepare()
  {
    std::cout << "Prepare" << std::endl;
    std::cout << "dough: " << _dough << std::endl;
    std::cout << "sauce: " << _sauce << std::endl;
    std::cout << "veggies: " << _veggies << std::endl;

    // _cheese = _factory->CreateCheese();
  }

  void Bake()
  {
    std::cout << "正在进行烘培操作" << std::endl;
  }

  void Cut()
  {
    std::cout << "将披萨提前切好" << std::endl;
  }

  void Box()
  {
    std::cout << "包装披萨" << std::endl;
  }

  ~NYStyleVeggiesPizza()
  {
    delete _factory;
  }
};

class NYStyleClamPizza : public Pizza
{
private:
  std::string _dough;
  std::string _sauce;
  std::string _clam;

public:
  NYStyleClamPizza()
      : Pizza(new NYIngredientFactory())
  {
    _dough = _factory->CreateDough();
    _sauce = _factory->CreateSauce();
    // 注意这里必须要强转，否则会调用基类的接口
    _clam = ((NYIngredientFactory *)_factory)->CreateClam();
  }

  // 获取原料
  void Prepare()
  {
    std::cout << "Prepare" << std::endl;
    std::cout << "dough: " << _dough << std::endl;
    std::cout << "sauce: " << _sauce << std::endl;
    std::cout << "clam: " << _clam << std::endl;

    // _cheese = _factory->CreateCheese();
  }

  void Bake()
  {
    std::cout << "正在进行烘培操作" << std::endl;
  }

  void Cut()
  {
    std::cout << "将披萨提前切好" << std::endl;
  }

  void Box()
  {
    std::cout << "包装披萨" << std::endl;
  }

  ~NYStyleClamPizza()
  {
    delete _factory;
  }
};

#endif